<template>
  <div class="row">
    <div class="col-4 mb-4" v-for="column in columnList" :key="column._id">
      <div class="card h-100 shadow-sm">
        <div class="card-body text-center">
          <img
            class="rounded-circle border border-light my-3"
            :src="column.avatar && column.avatar.fitUrl"
            :alt="column.title"
          />
          <h5 class="card-title">{{ column.title }}</h5>
          <p class="card-text text-start">{{ column.description }}</p>
          <router-link
            :to="{ name: 'Column', params: { id: column._id } }"
            class="btn btn-outline-primary"
          >
            进入专栏
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, PropType, computed } from 'vue'
import { TColumnList } from '@/types/index'
import { resetImagesStyle } from '@/utils'
export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<TColumnList>,
      required: true
    }
  },
  setup(props) {
    const columnList = computed(() => {
      return props.list.map((item) => {
        item.avatar = resetImagesStyle(item.avatar, 50, 50)
        return item
      })
    })
    return {
      columnList
    }
  }
})
</script>
